vrrp_script check_mysql {
    script "{{ mysql_data_dir_base }}/keepalived/check_mysql.sh"
    interval 10
    }

vrrp_instance VI_1 {
    interface {{ net_work_interface }}			#网卡根据实际修改
    virtual_router_id 130		#vip最后一段
    state BACKUP
    nopreempt
{% if master_ip in ansible_all_ipv4_addresses %}
    priority 150
{% else %}
    priority 100
{% endif %}
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
}
{% if master_ip in ansible_all_ipv4_addresses %}
        unicast_src_ip {{ master_ip }}    ##单播模式本地地址IP
        unicast_peer {
        {{ slave_ip }}     ##单播模式对端地址IP
{% else %}
        unicast_src_ip {{ slave_ip }}     ##单播模式本地地址IP
        unicast_peer {
        {{ master_ip }}     ##单播模式对端地址IP
{% endif %}
}
    track_script {
        check_mysql
    }
    virtual_ipaddress {
        {{ vip }}               ##改为实际分配的VIP
    }
    notify_fault  "{{ mysql_data_dir_base }}/keepalived/when_check_mysql_failed.sh"
    notify_master  "{{ mysql_data_dir_base }}/keepalived/when_become_master.sh"
    notify_backup  "{{ mysql_data_dir_base }}/keepalived/when_become_backup.sh"
    notify "{{ mysql_data_dir_base }}/when_status_change.sh"
    notify_stop "{{ mysql_data_dir_base }}/when_keepalived_normal_stop.sh"
}
